package com.iot.server.controller;

import com.alibaba.fastjson.JSONObject;
import com.iot.core.exception.BDException;
import com.iot.core.utils.R;
import com.iot.core.utils.StringUtil;
import com.iot.server.service.DictService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

/**
 * @author wuzt
 * Date 2019/10/24 15:26
 * Version 1.0
 * @ClassName DictController
 * Description
 **/
@RestController
@RequestMapping("sys/dict")
public class DictController {
    @Autowired
    DictService dictService;

    @PostMapping(value = "getDictByType", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public R getDictByType(@RequestBody JSONObject jsonObject) {
        if (!jsonObject.containsKey("dictType") || StringUtils.isEmpty(jsonObject.getString("dictType"))) {
            throw new BDException("设备类型不能为空");
        }
        return R.ok(dictService.getDictByType(jsonObject.getString("dictType")));
    }
}
